﻿using GalaSoft.MvvmLight;

namespace Mal.Balades.Admin
{
    public abstract class DataViewModelBase : ViewModelBase
    {
        #region Fields
        private bool isChanged;
        #endregion

        #region Construction / Destruction
        public DataViewModelBase()
        {
            this.PropertyChanged += new System.ComponentModel.PropertyChangedEventHandler(OnPropertyChanged);
        }
        #endregion

        #region enum, struct, class

        #endregion

        #region Properties
        /// <summary>
        /// Gets the object's changed status.
        /// </summary>
        public bool IsChanged
        {
            get { return isChanged; }
            set
            {
                if (isChanged != value)
                {
                    isChanged = value;
                    RaisePropertyChanged("IsChanged");
                }
            }
        }
        #endregion

        #region Methods
        /// <summary>
        /// Gets the the object's changed status.
        /// </summary>
        /// <returns></returns>
        protected abstract bool GetIsChanged();
        #endregion

        #region Events
        /// <summary>
        /// Unregisters this instance from the Messenger class.
        /// <para>To cleanup additional resources, override this method, clean
        /// up and then call base.Cleanup().</para>
        /// </summary>
        public override void Cleanup()
        {
            this.PropertyChanged -= new System.ComponentModel.PropertyChangedEventHandler(OnPropertyChanged);
            base.Cleanup();
        }

        void OnPropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
        {
            this.IsChanged = GetIsChanged();
        }
        #endregion
    }
}
